<?php
/**
 * Store
 * 
 * @category	Log
 * @package		dayscript.log.adapter
 * @subpackage	
 * @author		Nelson Daza <ndaza@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license		
 * @version		1.0
 * @version		$Revision: 0 $
 * @filesource	
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		
 * @since		1.0
 * @modifiedby	$LastChangedBy: Nelson Daza $
 * @modified	$Date: 2009-09-02 $
 */

namespace dayscript\log\adapter;

/**
 * Store
 * 
 * @category	Log
 * @package		dayscript.log.adapter
 * @subpackage	
 * @author		Nelson Daza <ndaza@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license		
 * @version		1.0
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		\dayscript\Map, \dayscript\log\Logger
 * @since		1.0
 * @modifiedby	$LastChangedBy: Nelson Daza $
 * @modified	$Date: 2009-09-03 $
 */
use dayscript;

class Store extends \dayscript\log\adapter\Output	{
	/**
	 * Store constructor
	 * @param string $name Store identificator
	 * @param array|\dayscript\Map $config File configuration
	 * @return Logger
	 */
	public function __construct( $name, \dayscript\Map $config )	{
		parent::__construct( $name, $config );
	}
	/**
	 * @see \dayscript\log\Logger
	 */
	public function internalLog( $message, $actualThreshold, $filterThreshold )	{
		if( $actualThreshold & $filterThreshold )
			$this->buffer[] = $message;
	}
	/**
	 * @see \dayscript\log\Logger
	 */
	public function flush( )	{
		// Override
	}
	
	public function getString( )	{
		$string = '';
		foreach( $this->buffer as $msg )	{
			$msg = \html_entity_decode( \str_replace( "\r", "", \rawurldecode( $msg ) ) );
			$file = $line = null;
			if( \dayscript\Enviroment::server( 'SERVER_NAME' ) != null && \headers_sent( $file, $line ) && $file && $file != __FILE__ )
				$msg = \nl2br( \str_replace( $this->htmlReserved, $this->htmlReplacement, \htmlentities ( $msg ) ) );
				// . ' : [' . $file . ':' . $line . ']';
			else
				$msg = \strip_tags( $msg );
			$string .= $msg;
		}
		return $string;
	}
	
}